<?php
require_once MODEL_DIR . 'Content/Content.php';
require_once MODEL_DIR . 'Content/ContentFactory.php';
require_once MODEL_DIR . 'User/User.php';
require_once MODEL_DIR . 'User/UserFactory.php';


/**
 * CMSParser is an implementaion of JankParser for the JankCMS 
 * application. It contains parse methods for the CMS-specific functions
 * of the application.
 *
 * @author Rick Hutcheson
 * @version 0.1
 */
class CMSParser extends JankParser {
    /**
     * The UserFactory to use for extracting user information from the jankCMS
     * data source.
     */
    private $userModel;
    
    /**
     * The ContentFacory to use for extracting content from the jankCMS data 
     * source.
     */
    private $contentModel;
    
    /**
     * Creates a new CMSParser, allowing us to parse templates associated with 
     * the jankCMS application.
     */
    public function __construct() {
        $this->userModel = new UserFactory();
        $this->contentModel = new ContentFactory();
    }
    
    /**
     * Replaces the {{site_location}} keyword.
     * @return string 
     *  The location of the application as a browser-safe link.
     */
    public function parseSiteLocation() {
        return APP_DIR_LINKS;
    }
    
    /**
     * Replaces the {{site_location}} keyword.
     * @return string 
     *  The title of the web site.
     */
    public function parseSiteTitle() {
        return SITE_TITLE;
    }
    
    /**
     * Replaces the {{section_title}} keyword.
     * @return string 
     *  The title of the current section, defined inside of the $values array.
     */
    public function parseSectionTitle() {
        return $this->values['section_title'];
    }
    

    /**
     * Replaces the {{error_message}} keyword.
     * @return string 
     *  An error message.
     */
    public function parseErrorMessage() {
        return $this->values['error_message'];
    }
        
    /**
     * Replaces the {{user_name}} keyword.
     * @return string 
     *  The current user's first and last name.
     */ 
    public function parseUserName() {
        if(isset($_SESSION['username'])) {
            $currentUser = $this->userModel->getUserFromUsername(
                                                        $_SESSION['username']);
            return $currentUser->getFirstName().' '.$currentUser->getLastName();
        }
    }
    
    /**
     * Replaces the {{page_content}} keyword.
     * @return string 
     *  The content of the current page, defined by the $values array.
     */ 
    public function parsePageContent() {
        return $this->values['page_content'];
    }
}

?>
